#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1010;
const int mod = 1e9+7;

ll fac[N],inv[N],f[N];
int siz[N],n,deg[N];
vector <int> G[N];

void link(int x,int y){G[x].pb(y);}

ll C(int x,int y){return fac[x] * inv[y] % mod * inv[x - y] % mod;}

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1) res=res*x%mod;return res;}

void solve(){
	for(int i = 1;i <= n;i++) G[i].clear();
	n = in; memset(deg,0,sizeof(deg)); memset(siz,0,sizeof(siz));
	for(int i = 1;i < n;i++){
		int x,y;char op; scanf("%d %c %d",&x,&op,&y);x++;y++;
		if(op == '<') link(x,y),deg[y]++;
		else link(y,x),deg[x]++;
	}
	queue<int> q; for(int i = 1;i <= n;i++) if(!deg[i]) q.push(i);
	for(int i = 1;i <= n;i++) f[i] = 1;
	ll ans = 1;
	while(q.size()){
		int x = q.front();q.pop();if(!G[x].size()) ans = ans * f[x] % mod;
		for(int y : G[x]){
			f[y] = f[x] * f[y] % mod * C(siz[x] + siz[y] + 1,siz[y]) % mod;
			siz[y] += siz[x]; if(!--deg[y]) q.push(y);
		}
	}
	printf("%lld\n",ans);
}

void init(){
	for(int i = (fac[0] = 1);i < N;i++) fac[i] = fac[i-1] * i % mod;
	inv[N-1] = qp(fac[N-1],mod-2);
	for(int i = N-2;i >= 0;i--) inv[i] = inv[i+1] * (i + 1) % mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	init();
	int T = in;while(T--) solve();
	return 0;
}
